﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// Ad数据类
    /// </summary>
    public class Ad
    {

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-12</date>
        /// <param name="fAdcd">广告编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string fAdcd, string fEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_ad");
            strSql.Append(" where FAdcd=@FAdcd and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAdcd", SqlDbType.VarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = fAdcd;
            parameters[1].Value = fEntityNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 获得多条图片存放路径
        /// </summary>
        /// <param name="strAdCds">编号字符</param>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>List集合</returns>
        public List<string> GetSrvName(string strAdCds, string strEntityNo)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FSvrFileName");
            strSql.Append(" FROM t_ad  where FAdcd in('");
            strSql.Append(strAdCds);
            strSql.Append("')");
            strSql.Append(" and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = strEntityNo;
            using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (sdr.Read())
                {
                    listStr.Add(sdr[0].ToString());
                }
            }

            return listStr;
        }


        /// <summary>
        /// 获得多条图片存放路径
        /// </summary>
        /// <param name="strAdCds">编号字符</param>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>集合</returns>
        public List<string> GetSrvName(string[] strAdCds, string strEntityNo)
        {
            List<string> listStr = new List<string>();
            StringBuilder strSql = new StringBuilder();
            SqlParameter[] parameters = new SqlParameter[] { };
            if (strAdCds.Length > 0)
            {
                strSql.Append("select FSvrFileName");
                strSql.Append(" FROM t_ad  where FAdcd in");
                strSql.Append("(");
                for (int i = 0; i < strAdCds.Length;i++ )
                {                  
                    if (i+1 == strAdCds.Length)
                    {
                        strSql.Append("'"+strAdCds[i]+"'");
                    }
                    else {
                        strSql.Append("'"+strAdCds[i]+"'" + ",");                   
                    }
                    
                }
                strSql.Append(")");
                strSql.Append(" and FEntityNo=@FEntityNo ");

                foreach (string adNo in strAdCds)
                {
                    parameters =new SqlParameter[] {
					    new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
                    parameters[0].Value = strEntityNo;
                  }
                DataSet ds = DbHelperSQL.Query(strSql.ToString(),parameters);

                foreach (DataRow dr in ds.Tables[0].Rows) {
                    listStr.Add(dr["FSvrFileName"].ToString());                   
                }
               
            }           
            return listStr;
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-8</date>
        /// </summary>
        /// <returns>集合</returns>
        public DataSet GetAdList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight ");
            strSql.Append(" FROM t_ad ");

            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取全屏广告的个数
        /// </summary>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>全屏广告的个数</returns>
        public int GetQPCount(string strEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  count(*) from t_ad ");
            strSql.Append(" where FEntityNo=@FEntityNo  and FAdProp='5'");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = strEntityNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return Int32.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }

        /// <summary>
        /// 获取左对联广告的个数
        /// </summary>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>左对联广告的个数</returns>
        public int GetLeftDlCount(string strEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  count(*) from t_ad ");
            strSql.Append(" where FEntityNo=@FEntityNo  and FAdProp='3'");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = strEntityNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return Int32.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }

        /// <summary>
        /// 获取右对联广告的个数
        /// </summary>
        /// <param name="strEntityNo">公司编号</param>
        /// <returns>右对联广告的个数</returns>
        public int GetRightDlCount(string strEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  count(*) from t_ad ");
            strSql.Append(" where FEntityNo=@FEntityNo  and FAdProp='4'");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.VarChar,50)};
            parameters[0].Value = strEntityNo;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                return Int32.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 批量删除广告数据 事务模式
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
        /// <param name="adNoArray">编号数组</param>
        /// <param name="entityNo">公司编号</param>
        public void DelManyAd(string[] adNoArray, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            
            if (adNoArray.Length > 0)
            {
                //删除广告数据
                strSql = new StringBuilder();
                strSql.Append("delete from t_ad ");
                strSql.Append(" where FAdcd=@FAdcd ");

                string strSqlAd = strSql.ToString();

                foreach (string adNo in adNoArray)
                {
                    cmds = new CommandInfo();
                  
                    SqlParameter[] parameters = {
					    new SqlParameter("@FAdcd", SqlDbType.NVarChar,15)	};

                    parameters[0].Value = adNo;

                    cmds.CommandText = strSqlAd;
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }

            }

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);

        }


        /// <summary>
        /// 删除数据 事务模式
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
       /// <param name="adNo">广告编号</param>
       /// <param name="entityNo">公司编号</param>
        public void DelAd(string adNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();


            //删除数据
            strSql.Append("delete from t_ad ");
            strSql.Append(" where FAdcd=@FAdcd ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAdcd", SqlDbType.VarChar,50)};

           parameters[0].Value = adNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);

        }


        /// <summary>
        /// 增加一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-11</date>
        /// </summary>
       /// <param name="model">model对象</param>
        public void Add(ElingOA6_Admin_DSJCJ.Model.Ad model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_ad(");
            strSql.Append("FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight)");
            strSql.Append(" values (");
            strSql.Append("@FAdcd,@FEntityNo,@FAdName,@FAdProp,@FDataType,@FOldFileName,@FSvrFileName,@FAdContent,@FAdType,@FAdUrl,@FIsUse,@FAdWidth,@FAdHeight)");
            SqlParameter[] parameters = {
					new SqlParameter("@FAdcd", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAdName", SqlDbType.VarChar,80),
					new SqlParameter("@FAdProp", SqlDbType.Char,1),
					new SqlParameter("@FDataType", SqlDbType.Char,1),
					new SqlParameter("@FOldFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FSvrFileName", SqlDbType.VarChar,255),
					new SqlParameter("@FAdContent", SqlDbType.Image,16),
					new SqlParameter("@FAdType", SqlDbType.VarChar,80),
					new SqlParameter("@FAdUrl", SqlDbType.VarChar,255),
					new SqlParameter("@FIsUse", SqlDbType.Decimal,5),
					new SqlParameter("@FAdWidth", SqlDbType.Int,4),
					new SqlParameter("@FAdHeight", SqlDbType.Int,4)};
            parameters[0].Value = model.FAdcd;
            parameters[1].Value = model.FEntityNo;
            parameters[2].Value = model.FAdName;
            parameters[3].Value = model.FAdProp;
            if (model.FDataType == "" || model.FDataType == null)
            {
                parameters[4].Value = DBNull.Value;
            }
            else
            {
                parameters[4].Value = model.FDataType;
            }
            if (model.FOldFileName == "" || model.FOldFileName == null)
            {
                parameters[5].Value = DBNull.Value;
            }
            else
            {
                parameters[5].Value = model.FOldFileName;
            }
            if (model.FSvrFileName == "" || model.FSvrFileName == null)
            {
                parameters[6].Value = DBNull.Value;
            }
            else
            {
                parameters[6].Value = model.FSvrFileName;
            }
            if (model.FAdContent == null)
            {
                parameters[7].Value = DBNull.Value;
            }
            else
            {
                parameters[7].Value = model.FAdContent;
            }
            parameters[8].Value = model.FAdType;
            parameters[9].Value = model.FAdUrl;
            parameters[10].Value = model.FIsUse;
            parameters[11].Value = model.FAdWidth;
            parameters[12].Value = model.FAdHeight;


            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 更新一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-12</date>
        /// </summary>
        /// <param name="model">对象</param>
        public void Update(ElingOA6_Admin_DSJCJ.Model.Ad model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_ad set ");
            strSql.Append("FAdName=@FAdName,");
            strSql.Append("FAdProp=@FAdProp,");
            strSql.Append("FDataType=@FDataType,");
            strSql.Append("FOldFileName=@FOldFileName,");
            strSql.Append("FSvrFileName=@FSvrFileName,");
            strSql.Append("FAdContent=@FAdContent,");
            strSql.Append("FAdType=@FAdType,");
            strSql.Append("FAdUrl=@FAdUrl,");
            strSql.Append("FIsUse=@FIsUse,");
            strSql.Append("FAdWidth=@FAdWidth,");
            strSql.Append("FAdHeight=@FAdHeight");
            strSql.Append(" where FAdcd=@FAdcd and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAdcd", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAdName", SqlDbType.VarChar,80),
					new SqlParameter("@FAdProp", SqlDbType.Char,1),
					new SqlParameter("@FDataType", SqlDbType.Char,1),
                    new SqlParameter("@FOldFileName", SqlDbType.VarChar,255),
                    new SqlParameter("@FSvrFileName", SqlDbType.VarChar,255),
                    new SqlParameter("@FAdContent", SqlDbType.Image,16),
                    new SqlParameter("@FAdType", SqlDbType.VarChar,80),
					new SqlParameter("@FAdUrl", SqlDbType.VarChar,255),
					new SqlParameter("@FIsUse", SqlDbType.Decimal,5),
					new SqlParameter("@FAdWidth", SqlDbType.Int,4),
					new SqlParameter("@FAdHeight", SqlDbType.Int,4)};
            parameters[0].Value = model.FAdcd;
            parameters[1].Value = model.FEntityNo;
            parameters[2].Value = model.FAdName;
            parameters[3].Value = model.FAdProp;
            if (model.FDataType == "" || model.FDataType == null)
            {
                parameters[4].Value = DBNull.Value;
            }
            else
            {
                parameters[4].Value = model.FDataType;
            }
            if (model.FOldFileName == "" || model.FOldFileName == null)
            {
                parameters[5].Value = DBNull.Value;
            }
            else
            {
                parameters[5].Value = model.FOldFileName;
            }
            if (model.FSvrFileName == "" || model.FSvrFileName == null)
            {
                parameters[6].Value = DBNull.Value;
            }
            else
            {
                parameters[6].Value = model.FSvrFileName;
            }
            if (model.FAdContent == null)
            {
                parameters[7].Value = DBNull.Value;
            }
            else
            {
                parameters[7].Value = model.FAdContent;
            }
            parameters[8].Value = model.FAdType;
            parameters[9].Value = model.FAdUrl;
            parameters[10].Value = model.FIsUse;
            parameters[11].Value = model.FAdWidth;
            parameters[12].Value = model.FAdHeight;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        ///// <summary>
        ///// 更新一条数据
        ///// <creator>chenly</creator>
        ///// <date>2013-7-12</date>
        ///// </summary>
        ///// <param name="model">对象</param>
        //public void UpdateImg(ElingOA6_Admin_DSJCJ.Model.Ad model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("update t_ad set ");
        //    strSql.Append("FAdName=@FAdName,");
        //    strSql.Append("FAdProp=@FAdProp,");
        //    strSql.Append("FDataType=@FDataType,");
        //    strSql.Append("FOldFileName=@FOldFileName,");
        //    strSql.Append("FSvrFileName=@FSvrFileName,");
        //    strSql.Append("FAdContent=@FAdContent,");
        //    strSql.Append("FAdType=@FAdType,");
        //    strSql.Append("FAdUrl=@FAdUrl,");
        //    strSql.Append("FIsUse=@FIsUse,");
        //    strSql.Append("FAdWidth=@FAdWidth,");
        //    strSql.Append("FAdHeight=@FAdHeight");
        //    strSql.Append(" where FAdcd=@FAdcd and FEntityNo=@FEntityNo ");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@FAdcd", SqlDbType.VarChar,30),
        //            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
        //            new SqlParameter("@FAdName", SqlDbType.VarChar,80),
        //            new SqlParameter("@FAdProp", SqlDbType.Char,1),
        //            new SqlParameter("@FDataType", SqlDbType.Char,1),
        //            new SqlParameter("@FOldFileName", SqlDbType.VarChar,255),
        //            new SqlParameter("@FSvrFileName", SqlDbType.VarChar,255),
        //            new SqlParameter("@FAdContent", SqlDbType.Image,16),
        //            new SqlParameter("@FAdType", SqlDbType.VarChar,80),
        //            new SqlParameter("@FAdUrl", SqlDbType.VarChar,255),
        //            new SqlParameter("@FIsUse", SqlDbType.Decimal,5),
        //            new SqlParameter("@FAdWidth", SqlDbType.Int,4),
        //            new SqlParameter("@FAdHeight", SqlDbType.Int,4)};
        //    parameters[0].Value = model.FAdcd;
        //    parameters[1].Value = model.FEntityNo;
        //    parameters[2].Value = model.FAdName;
        //    parameters[3].Value = model.FAdProp;
        //    parameters[4].Value = model.FDataType;
        //    parameters[5].Value = model.FOldFileName;
        //    parameters[6].Value = model.FSvrFileName;
        //    parameters[7].Value = model.FAdContent;
        //    parameters[8].Value = model.FAdType;
        //    parameters[9].Value = model.FAdUrl;
        //    parameters[10].Value = model.FIsUse;
        //    parameters[11].Value = model.FAdWidth;
        //    parameters[12].Value = model.FAdHeight;

        //    DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        //}

        /// <summary>
        /// 获取图片二进制流
        /// <creator>chenly</creator>
        /// <date>2013-7-12</date>
        /// </summary>
        /// <param name="adNo">广告编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>获取图片二进制流</returns>
        public byte[] GetPhoto(string adNo, string entityNo)
        {
            string strSql = "select  top 1 FAdContent from t_ad where FEntityNo=@FEntityNo and FAdcd=@FAdcd ";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FAdcd", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = adNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return (byte[])obj;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 更新系统相关信息
        /// <creator>chenly</creator>
        /// <date>2013-7-16</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="fAdContent">广告内容</param>
        /// <param name="fSvrFileName">广告地址</param>
        /// <param name="fAdType">广告类型</param>
        /// <param name="fOldFileName">原来的名字</param>
        public void UpdateFile(string entityNo, byte[] fAdContent, string fSvrFileName,
            string fAdType, string fOldFileName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_ad set ");
            strSql.Append("fAdContent=@fAdContent,");
            strSql.Append("fSvrFileName=@fSvrFileName,");
            strSql.Append("fAdType=@fAdType,");
            strSql.Append("fOldFileName=@fOldFileName");
            strSql.Append(" where FAdcd=@FAdcd");
            SqlParameter[] parameters = {
				    new SqlParameter("@FAdcd", SqlDbType.VarChar,12),
					new SqlParameter("@fAdContent", SqlDbType.Image),
					new SqlParameter("@fSvrFileName", SqlDbType.VarChar,255),
					new SqlParameter("@fAdType", SqlDbType.VarChar,80),
					new SqlParameter("@fOldFileName", SqlDbType.VarChar,255)};
            parameters[0].Value = entityNo;
            parameters[1].Value = fAdContent;
            parameters[2].Value = fSvrFileName;
            parameters[3].Value = fAdType;
            parameters[4].Value = fOldFileName;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="fAdNo">广告编号</param>
        /// <returns>实体对象</returns>
        public Model.Ad GetModel(string entityNo, string fAdNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FAdcd, FEntityNo, FAdName, FAdProp, FDataType, FOldFileName, FSvrFileName, FAdContent, FAdType, FAdUrl, FIsUse, FAdWidth, FAdHeight from t_ad ");
            strSql.Append(" where FAdcd=@FAdcd ");
            SqlParameter[] parameters = {
					new SqlParameter("FAdcd", SqlDbType.NVarChar,15)			};
            parameters[0].Value = fAdNo;

            Model.Ad model = new Model.Ad();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FAdcd"] != null && ds.Tables[0].Rows[0]["FAdcd"].ToString() != "")
                {
                    model.FAdcd = ds.Tables[0].Rows[0]["FAdcd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEntityNo"] != null && ds.Tables[0].Rows[0]["FEntityNo"].ToString() != "")
                {
                    model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAdName"] != null && ds.Tables[0].Rows[0]["FAdName"].ToString() != "")
                {
                    model.FAdName = ds.Tables[0].Rows[0]["FAdName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAdProp"] != null && ds.Tables[0].Rows[0]["FAdProp"].ToString() != "")
                {
                    model.FAdProp = ds.Tables[0].Rows[0]["FAdProp"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FDataType"] != null && ds.Tables[0].Rows[0]["FDataType"].ToString() != "")
                {
                    model.FDataType = ds.Tables[0].Rows[0]["FDataType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FOldFileName"] != null && ds.Tables[0].Rows[0]["FOldFileName"].ToString() != "")
                {
                    model.FOldFileName = ds.Tables[0].Rows[0]["FOldFileName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSvrFileName"] != null && ds.Tables[0].Rows[0]["FSvrFileName"].ToString() != "")
                {
                    model.FSvrFileName = ds.Tables[0].Rows[0]["FSvrFileName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAdContent"] != null && ds.Tables[0].Rows[0]["FAdContent"].ToString() != "")
                {
                    model.FAdContent = (byte[])ds.Tables[0].Rows[0]["FAdContent"];
                }
                if (ds.Tables[0].Rows[0]["FAdType"] != null && ds.Tables[0].Rows[0]["FAdType"].ToString() != "")
                {
                    model.FAdType = ds.Tables[0].Rows[0]["FAdType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAdUrl"] != null && ds.Tables[0].Rows[0]["FAdUrl"].ToString() != "")
                {
                    model.FAdUrl = ds.Tables[0].Rows[0]["FAdUrl"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FIsUse"] != null && ds.Tables[0].Rows[0]["FIsUse"].ToString() != "")
                {
                    model.FIsUse = (decimal)ds.Tables[0].Rows[0]["FIsUse"];
                }
                if (ds.Tables[0].Rows[0]["FAdWidth"] != null && ds.Tables[0].Rows[0]["FAdWidth"].ToString() != "")
                {
                    model.FAdWidth = (int)ds.Tables[0].Rows[0]["FAdWidth"];
                }
                if (ds.Tables[0].Rows[0]["FAdHeight"] != null && ds.Tables[0].Rows[0]["FAdHeight"].ToString() != "")
                {
                    model.FAdHeight = (int)ds.Tables[0].Rows[0]["FAdHeight"];
                }
               
                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight ");
            strSql.Append(" FROM t_ad ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.Ad DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.Ad model = new ElingOA6_Admin_DSJCJ.Model.Ad();
            if (row != null)
            {
                if (row["FAdcd"] != null)
                {
                    model.FAdcd = row["FAdcd"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FAdName"] != null)
                {
                    model.FAdName = row["FAdName"].ToString();
                }
                if (row["FAdProp"] != null)
                {
                    model.FAdProp = row["FAdProp"].ToString();
                }
                if (row["FDataType"] != null)
                {
                    model.FDataType = row["FDataType"].ToString();
                }
                if (row["FOldFileName"] != null)
                {
                    model.FOldFileName = row["FOldFileName"].ToString();
                }
                if (row["FSvrFileName"] != null)
                {
                    model.FSvrFileName = row["FSvrFileName"].ToString();
                }
                if (row["FAdContent"] != null && row["FAdContent"].ToString() != "")
                {
                    model.FAdContent = (byte[])row["FAdContent"];
                }
                if (row["FAdType"] != null)
                {
                    model.FAdType = row["FAdType"].ToString();
                }
                if (row["FAdUrl"] != null)
                {
                    model.FAdUrl = row["FAdUrl"].ToString();
                }
                if (row["FIsUse"] != null && row["FIsUse"].ToString() != "")
                {
                    model.FIsUse = decimal.Parse(row["FIsUse"].ToString());
                }
                if (row["FAdWidth"] != null && row["FAdWidth"].ToString() != "")
                {
                    model.FAdWidth = int.Parse(row["FAdWidth"].ToString());
                }
                if (row["FAdHeight"] != null && row["FAdHeight"].ToString() != "")
                {
                    model.FAdHeight = int.Parse(row["FAdHeight"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (top > 0)
            {
                strSql.Append(" top " + top.ToString());
            }
            strSql.Append(" FAdcd,FEntityNo,FAdName,FAdProp,FDataType,FOldFileName,FSvrFileName,FAdContent,FAdType,FAdUrl,FIsUse,FAdWidth,FAdHeight ");
            strSql.Append(" FROM t_ad ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


    }
}
